//
//  DCSendOrderCell.m
//  Driver
//
//  Created by 大橙子 on 2018/11/8.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCSendOrderCell.h"
@interface DCSendOrderCell ()
@property (nonatomic,strong) DCImageAndTextLabel *priceLabel;
@property (nonatomic,strong) UIView *thirdView;
@property (nonatomic,strong) UIButton *phoneBtn;
@property (nonatomic,strong) UIButton *tapBtn;
@end
@implementation DCSendOrderCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCSendOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCSendOrderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = BackgroundColor;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    [self setUpBaseUI];
    self.priceLabel = [[DCImageAndTextLabel alloc]init];
//    self.priceLabel.backgroundColor = BlueColor;
    self.priceLabel.imageView.image = IMAGENAME(@"钱盾");
    self.priceLabel.textLabel.textColor = BlueColor;
    [self.secondView addSubview:self.priceLabel];
    
    self.thirdView = [[UIView alloc]init];
    self.thirdView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.thirdView];
    
    UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [tapBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [tapBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    tapBtn.titleLabel.font = FONT(15);
    tapBtn.layer.cornerRadius = 15;
    tapBtn.clipsToBounds = YES;
    tapBtn.layer.borderColor = BlueColor.CGColor;
    tapBtn.layer.borderWidth = 1;
    tapBtn.tag = 1;
    self.tapBtn = tapBtn;
    [self.thirdView addSubview:tapBtn];
    
    UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [phoneBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [phoneBtn setImage:IMAGENAME(@"电话") forState:UIControlStateNormal];
    phoneBtn.tag = 0;
    self.phoneBtn = phoneBtn;
    [self.thirdView addSubview:phoneBtn];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setUpLayoutSubviews];
    self.priceLabel.frame = CGRectMake(self.numLabel.right+5, self.carLabel.y, self.secondView.width - self.carLabel.width - self.totalNumLabel.width - self.numLabel.width-5, self.numLabel.height);
    self.thirdView.frame = CGRectMake(0, self.secondView.bottom+1, self.width, kBaseHeight);
    self.tapBtn.frame = CGRectMake(self.thirdView.width - 90*WIDTHSCALE6, 5, 80*WIDTHSCALE6, self.thirdView.height-10);
    self.phoneBtn.frame = CGRectMake(self.thirdView.width - self.tapBtn.width -55, 5, 30, 30);
}
-(void)setModel:(DCSendOrderModel *)model
{
    _model = model;
    self.carrierLabel.text = model.carrier;
    self.timeLabel.text = model.time;
    self.stateLabel.text = model.type;
    self.stateLabel.textColor = [UIColor redColor];
    
    self.startLabel.textLabel.text = @"北京顺义";
    self.extractLabel.textLabel.text = @"北京市顺义华阳库";
    self.endLabel.textLabel.text = @"上海浦东";
    self.sendLabel.textLabel.text = @"上海浦东XX街10号4S店";
    
    self.carLabel.textLabel.text = @"新车";
    self.totalNumLabel.text = @"6辆";
    self.numLabel.attributedText = [YLAttributedStr changNumberColorWithTotalString:@"(SUV3CAR3)" andColor:BlueColor];
    
    self.priceLabel.textLabel.text = @"80000元";
    
    if ([model.type isEqualToString:@"待成交"]) {
        [self.tapBtn setTitle:@"取消订单" forState:UIControlStateNormal];
    }else{
        [self.tapBtn setTitle:@"订单追踪" forState:UIControlStateNormal];
    }
}

-(void)btnDidClick:(UIButton *)button
{
    if (button.tag == 0) {
        DCLog(@"打电话");
        [DCTool call:@"17600907892"];
    }else{
        if ([self.model.type isEqualToString:@"待成交"]) {
            if (_delegate && [_delegate respondsToSelector:@selector(selectedWithCompleteBtn:)]) {
                [_delegate selectedWithCompleteBtn:@"取消订单"];
            }
        }else{
            DCLog(@"订单追踪");
            if (_delegate && [_delegate respondsToSelector:@selector(selectedWithLocationBtn:)]) {
                [_delegate selectedWithLocationBtn:@"location"];
            }
        }
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
